package com.hznu.ez4life.modules.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.hznu.ez4life.modules.entity.Building;
import com.hznu.ez4life.modules.entity.Item;
import com.hznu.ez4life.modules.dao.ItemDao;
import com.hznu.ez4life.modules.service.BuildingService;
import com.hznu.ez4life.modules.service.ItemService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hznu.ez4life.modules.service.ItemtypeService;
import com.hznu.ez4life.modules.service.StationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DragonDoor
 * @since 2019-07-25
 */
@Service
public class ItemServiceImpl extends ServiceImpl<ItemDao, Item> implements ItemService {

    @Autowired
    StationService stationService;
    @Autowired
    ItemtypeService itemtypeService;

    @Override
    public List<Item> findList(Integer userid)
    {
        List<Item> itemList = this.selectList(new EntityWrapper<Item>().eq("user_id",userid));
        for(Item item : itemList)
        {
            setDetail(item);
        }
        return itemList;
    }

    @Override
    public Item findById(Integer id)
    {
        Item item = this.selectById(id);
        setDetail(item);
        return item;
    }

    private void setDetail(Item item)
    {
        if(item.getStationId()!=null)
        {
            item.setStation(stationService.selectById(item.getStationId()));
        }
        if(item.getItemtypeId()!=null)
        {
            item.setItemtype(itemtypeService.selectById(item.getItemtypeId()));
        }
    }
}
